"use strict";

$(document).ready(function(){
	console.log('group_search....loading.....');
});


$(function() {
	$('#group_search').click(searchGroup);

});

function searchGroup() {
	console.log('search_groupping...');
	
	if(isPermitRegisterForm()) {
		console.log($('#g_SEARCH').val());
		
		new ajaxObject('../../group/searchGroup.do', {	
			group_Name:	$('#g_SEARCH').val()
		}, function(result) { 
			
			var groupSearchList = result.groupSearchList;
		
			//console.log(groupSearchList[0].group_No);
			
			
			$('#searchResultUl').html('');
			
			$.each(groupSearchList,function(index,group){
				
				console.log(group.group_No);
				console.log(group.group_Inf);
				
				$('#searchResultUl')
				.append('<li>')
				.append('<a href="#">')
				.append('<section>')
				.append('<img src=\"http://placehold.it/45x45\" alt : \"img\"/>')
				.append('<span>'+  group.group_No + '</span> ')
				.append('<span>'+  group.group_Name + '</span> ')
				.append('<span>'+  group.group_Inf + '</span> ')
				.append('<span>'+  group.group_Date + '</span> ')
				.append('<span>'+  group.group_Question + '</span> ')
				.append('<span>'+  group.group_Admin + '</span> ')
				.append('</section>')
				.append('</a>')
				.append('</li>');				
			});
		});
	}
	else {
		alert('검색폼을 제대로 입력해주세요.');
	}
	return false;
}

function isPermitRegisterForm() {
	if($('#g_SEARCH').val() === '' || $('#g_SEARCH').val() === null)
		return false;
	
	return true;
}

